const { Controller } = require('egg')
const dayjs = require('dayjs')

class ApiController extends Controller {
  /**
   * @api {get} /page/home [态势总览]
   * @apiGroup Page
   * @apiDescription 态势总览-页面中间模块
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": {
          // 中间区域
          "street": 0, // 街道
          "village": 0, // 村
          "xq": 0, // 小区
          "cz": 0, // 全县常住人口
          "fcz": 0, // 全县非常住人口
      }
  }
   */
  // 获取场所扫码数据
  async home() {
    const { ctx } = this
    const data = await this.service.trackData.getData(`home_info`)

    const returnData = {
      street: data.jd,
      village: data.jhw,
      xq: data.xq,
      cz: data.cz,
      fcz: data.fcz,
    }

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /page/code [场所码]
   * @apiGroup Page
   * @apiDescription 场所码
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": {
          // 基础信息
          "baseInfo": [
              {
                  "placeCategory": "商超", // 场所分类
                  "placeNum": 500, // 场所数量
                  "scanNum": 23085 // 扫码次数
              }
          ],
          "cz": 467, // 常住人口
          "fcz": 500, // 非常住人口
          "scanNum": 999 // 扫码总数
      }
  }
   */
  // 获取场所扫码数据
  async code() {
    const { ctx } = this
    const { query } = ctx
    const data = await this.service.trackData.getData(`code_info`)

    console.log('data', data)

    ctx.body = {
      code: 0,
      msg: 'success',
      data: {
        ...data,

        czTotal: data.cz,
        fczTotal: data.fcz,
        // scanNum: data.scanNum,
      },
    }
  }

  /**
   * @api {get} /page/hs [核酸检测]
   * @apiGroup Page
   * @apiDescription 核酸检测-今日核酸检测情况
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": {
          // 今日核酸检测情况
          "baseInfo": [
              {
                  "label": "应检",
                  "value": 0
              },
              {
                  "label": "已检",
                  "value": 0
              },
              {
                  "label": "未检",
                  "value": 0
              },
              {
                  "label": "检测率",
                  "value": 0
              }
          ]
      }
  }
   */
  async hs() {
    const { ctx } = this
    const { query } = ctx
    const data = await this.service.trackData.getData(`hs_info`)

    const returnData = {
      baseInfo: [
        {
          label: '应检',
          value: data.yingjian,
        },
        {
          label: '已检',
          value: data.yijian,
        },
        {
          label: '未检',
          value: data.weijian,
        },
        {
          label: '检测率',
          value: data.jcl,
        },
      ],
    }

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  /**
   * @api {get} /page/report [返乡报备]
   * @apiGroup Page
   * @apiDescription 返乡报备-页面中间模块
   * 
   * @apiParam {String} [scope=day] 范围 day（天）、week（周）、month（月）
   * 
   * @apiSuccessExample {json} Success-Response:
  {
      "code": 0,
      "msg": "success",
      "data": {
          "zrs": 0, // 返乡总人数
          "hc": 0, // 火车返乡人数
          "ctqc": 0, // 通过长途汽车返乡人数
          "zj": 0, // 通过自驾返乡人数
          "gfx": 0, // 到达高风险人数
          "hsrs": 0, // 到达高风险人数
          "hsjcl": 0 // 返乡核酸检测率
      }
  }
   */
  async report() {
    const { ctx } = this
    const { query } = ctx
    const scope = query.scope || 'day'
    const data = await this.service.trackData.getData(`${scope}_report_info`)

    const returnData = {
      ...data,
    }

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }
}

module.exports = ApiController
